package com.sjq.controller;


import com.sjq.model.common.BaseResult;
import com.sjq.model.entity.Classification;
import com.sjq.service.IClassificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @author sjq
 * @date 2021-12-08
 */
@Api( tags = "分类接口")
@RestController
@RequestMapping("/classification")
public class classificationController
{
    @Autowired
    private IClassificationService topicClassificationService;

    /**
     * 获取分类详细信息
     */
    @GetMapping(value = "/{id}")
    public BaseResult getInfo(@PathVariable("id") Long id)
    {
       return BaseResult.success("修改成功",topicClassificationService.selectClassificationById(id));
    }

    /**
     * 查询分类列表
     */
    @ApiOperation("查询所有分类列表")
    @GetMapping("/list")
    @RequiresAuthentication
    public BaseResult list(@RequestHeader String Authorization)
    {

        List<Classification> list = topicClassificationService.selectClassificationListAll();
        return BaseResult.success("查询成功",list);
    }


    /**
     * 新增分类
     */
    @ApiOperation("新增分类")
    @PostMapping
    public BaseResult add(@RequestBody Classification topicClassification)
    {
        if(topicClassificationService.insertClassification(topicClassification)>0){
            return BaseResult.success("新增成功");
        }
        return BaseResult.success("新增失败");
    }

    /**
     * 修改分类
     */
    @ApiOperation("修改分类")
    @PutMapping
    public BaseResult edit(@RequestBody Classification topicClassification)
    {
        if(topicClassificationService.updateClassification(topicClassification)>0){
            return BaseResult.success("修改成功");
        }
        return BaseResult.success("修改失败");
    }

    /**
     * 删除分类
     */
    @ApiOperation("删除分类")
    @DeleteMapping("/{ids}")
    public BaseResult remove(@PathVariable Long[] ids)
    {
        if(topicClassificationService.deleteClassificationByIds(ids)>0){
            return BaseResult.success("删除成功");
        }
        return BaseResult.success("删除失败");
    }
}
